// index.js
// 获取应用实例
import dayjs from "../../utils/dayjs.min";
// 引用百度地图微信小程序JSAPI模块 

const {
  windowHeight
} = wx.getSystemInfoSync()

import {
  wx_login,
  get_user_num
} from "../../api/login/login_user.js";
import {
  get_show,
  get_kebiao,
  get_lunbo,
  showAnnouncement,
  bind_qinglv,
  get_qinglv
} from "../../api/shool/get_score.js";
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
const app = getApp()

// const RSA = require('../../utils/password_util.js');

Page({
  //获取当前版本号

  onShareAppMessage(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      //生成转发5分钟后的时间戳
      let timestamp = dayjs().add(5, 'minute').valueOf();
      console.log(timestamp)
      return {
        title: this.data.user.name.value + '邀请你绑定情侣课表',
        path: '/pages/index/index?id=' + this.data.user.stuNumber.value + '&timestamp=' + timestamp,
        imageUrl: 'https://s2.loli.net/2022/05/01/vy1L4YQ6Cadwjzf.png'
      }
    }

  },

  //微信登录
  //登录
  login: function () {
    wx.login({
      success(res) {

        wx_login({
          code: res.code,
        }).then(res => {
          if (res.data.statusCode == 200) {
            //存入用户openid到缓存
            wx.setStorageSync('openid', res.data.data.openid)
          }

        })
      }
    })


  },

  //获取权限
  get_wx_info() {
    wx.getUserProfile({
      desc: '用于显示评论信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {

        //存入用户信息到缓存
        wx.setStorageSync('wx_user_info', res.userInfo)

      }
    })
  },

  //更新版本
  updated() {
    const updateManager = wx.getUpdateManager()

    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调


    })

    updateManager.onUpdateReady(function () {
      console.log('ddd')
      let text = ''
      // if (wx.getStorageSync('frist_login')) {
      text = '新版本已经准备好，是否重启应用？'
      // } else {
        wx.removeStorageSync('userinfo'),
          wx.removeStorageSync('token'),
          wx.removeStorageSync('dayke_list'),
          wx.removeStorageSync('ke_list'),
          wx.removeStorageSync('kebiao_list'),
          wx.removeStorageSync('openid'),
          wx.removeStorageSync('wx_user_info'),
          wx.removeStorageSync('user'),
          wx.removeStorageSync('announcement'),
          wx.removeStorageSync('ke_time')
      //   text = '新版本已经准备好，是否重启应用？(本次版本你需要重新登录)'
      // }


      wx.showModal({
        title: '更新提示',
        content: text,
        success(res) {
          if (res.confirm) {

            // wx.navigateTo({
            //   url: '/pages/login/login',
            // })
            // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate()
          }
        }
      })
    })

    updateManager.onUpdateFailed(function () {
      // 新版本下载失败
    })
  },
  //获取用户人数
  get_user_num() {


    get_user_num().then(res => {
      if (res.data.statusCode == 200) {
        this.setData({
          index_4: Math.floor(Math.random() * this.data.colorList.length),
          people_num: res.data.data
        })
      }
    })
  },

  //获取轮播图
  get_lunbo() {
    get_lunbo().then(res => {
      wx.hideLoading()
      this.setData({
        lunbo_list: res.data.data
      })
    })
  },
  //获取公告
  showAnnouncement() {
    showAnnouncement().then(res => {
      if (res.statusCode == 200) {
        if (wx.getStorageSync('announcement') && wx.getStorageSync('announcement') == res.data.data.length) {

        } else {
          wx.setStorageSync('announcement', res.data.data.length)
          this.setData({
            show: true,
          })
        }


        let result = null
        let arr = res.data.data
        // .map(item => {
        //   result = app.towxml(`> node.js `, 'markdown');
        //   return {
        //     title: item.title,
        //     create_time: item.create_time,
        //     text: result,
        //     id: item.id
        //   }


        // })

        // setTimeout(() => {

        this.setData({
          gonggao_list: arr,
          gg: res.data.data[0].text
        })
        // }, 1000)


      }

    }).catch(err => {

      wx.showToast({
        title: '网络异常',
        icon: 'none',
        duration: 10000
      })
    })
  },

  getUserInfo() {
    let user = wx.getStorageSync('user')
    if (user.birthday) {
      this.data.is_love_kebiao = true

      this.setData({

        is_love_kebiao: true
      })

    } else {

      this.data.is_love_kebiao = false
      this.setData({

        is_love_kebiao: false
      })
    }


  },

  onClose() {
    this.setData({
      show: false
    });
  },

  data: {
    //累计人数
    people_num: '000',
    index_4: 0, //随机颜色
    colorList: [
      "#08D8D1",
      "#FFD258",
      "#FF8771",
      "#5E99FB",
      "#12DB7E",
      "#9069F8",
      "#FA82DA",
      "#FFAE5D",
      '#2ea3e7',
      '#24af63',
      '#b92828',
      '#991dd3',
      '#6a18ec'
    ],

    is_love_kebiao: false,

    weather: [],
    stuta: false, //空调开启状态
    wendu: 21, //空调温度
    type: 0, //空调类型
    gg_index: 0,
    inter: '',
    gg: '',

    arr: [],
    day_type: 1,
    time_list: [],
    ke_list: [],
    time: '',
    wlist: [],
    week: [],
    list: [],

    time_2: [
      [
        "08:00",
        "08:45"
      ],
      [
        "08:55",
        "09:40"
      ],
      [
        "10:25",
        "11:10"
      ],
      [
        "11:15",
        "12:00"
      ],
      [
        "14:00",
        "14:45"
      ],
      [
        "14:50",
        "15:35"
      ],
      [
        "15:55",
        "16:40"
      ],
      [
        "16:45",
        "17:30"
      ],
      [
        "18:30",
        "19:15"
      ],
      [
        "19:20",
        "20:05"
      ]
    ],


    show: false,
    type_1: null,

    grid_list: [
      [{
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:22:40.216.jpg',
          text: 'CET',
          url: "/pages/CET/CET",
          id: 101
        },
        {
          icon: ' https://cdn.manoushang.com/file/2022-07-19T22:25:26.798.jpg ',
          text: '外卖超市',
          is_open: 1,
          // url: '/pages/xueke_data/xuanke_data',
          type: 'waimai',
          id: 105
        },


        {
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:26:54.953.jpg',
          text: '课表',
          url: "/pages/kebiao/kebiao",
          id: 103
        },
        {
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:28:02.302.jpg',
          // icon: 'https://s2.loli.net/2022/05/10/vE47Rnjmp3M5g9q.png'  
          text: '一键评教',
          url: '/pages/wyy/wyy',
          id: 108
        },

        {
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:28:31.996.jpg',
          text: '学生成绩',
          id: 105,
          url: '/pages/xueqi_score/xq_seore'
        },
        {
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:28:55.012.jpg',
          text: '考试安排',
          url: '/pages/index_1/index',
          id: 106
        },
        {
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:29:35.136.jpg',
          text: '公告',
          // url: '/pages/index_1/index',
          type: 'gonggao',
          id: 107
        },
        {
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:30:25.153.jpg',
          text: '校园墙',
          url: '/pages/liuyan/liuyan',
          type: 'liuyan',
          id: 108
        },
        {
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:30:51.925.jpg',
          text: '琉璃壁纸',
          url: '/pages/image_zy/image_zy',
          type: 'img',
          id: 108
        },
        {
          icon: 'https://cdn.manoushang.com/file/2022-07-19T22:31:20.686.jpg',
          text: '搜题帮',
          url: '/pages/souti/souti',

          id: 108
        }
      ]
    ],
    dxcodeImg: '',
    user: app.globalData.userInfo
  },
  //获取天气
  getWeather: function () {
    console.log('请求天气')
    try {
      var that = this;
      //获取生活指数
      wx.request({
        url: 'https://devapi.qweather.com/v7/indices/1d',
        data: {
          // key: 'f63aeacd092e4545b5b56b15dae2999e',
          key: '7cfcbda7cc39494caae276823a8bfa25',
          //小数点后两位
          location: that.data.user.project.value == '武汉学院' ? '101200105' : '101200111',
          type: 0
        },
        success: function (res) {
          // var weather = res.data.HeWeather6[0].now;

          that.setData({
            // weather: res.data.now
            weather_arr: res.data.daily
          })
        }
      })

      //获取天气
      wx.request({
        url: 'https://devapi.qweather.com/v7/weather/now',
        data: {
          // key: 'f63aeacd092e4545b5b56b15dae2999e',
          key: '7cfcbda7cc39494caae276823a8bfa25',
          //小数点后两位
          location: that.data.user.project.value == '武汉学院' ? '101200105' : '101200111',

        },
        success: function (res) {
          // var weather = res.data.HeWeather6[0].now;

          that.setData({
            weather: res.data.now
            // weather_arr: res.data.daily
          })
        }
      })
    } catch (e) {

    }



  },


  //生成一周日期列表
  getWeekList: function () {
    let now = new Date();
    let nowM = now.getMonth() + 1;
    let nowD = now.getDate();
    let nowY = now.getFullYear();
    let nowH = now.getHours();
    let nowMi = now.getMinutes();
    let nowS = now.getSeconds();
    let nowTime = nowY + "-" + nowM + "-" + nowD + " " + nowH + ":" + nowMi + ":" + nowS;
    this.data.time = dayjs(nowTime).format("MM/DD");

    let now_1 = dayjs(nowTime).format("YYYY-MM-DD");
    let end_1=null
try{
   end_1 = wx.getStorageSync('userinfo').options.start_time //起始学期
}catch(err){
   end_1 ='2020-08-29' //起始学期
}
    


    this.data.nowW = parseInt(this.DateDiff(end_1, now_1) / 7 + 1)
    this.data.nowM = dayjs(nowTime).format("M");
    this.data.nowW_1 = this.data.nowW
    //生成一周日期列表
    this.GetMonday()
    this.setData({
      time: this.data.time,
    })

  },
  //生成一周列表
  GetMonday() {

    let h = this.data.nowW - this.data.nowW_1 - 1
    // let h = 3
    let weekList = [];
    let arr = ['一', '二', '三', '四', '五', '六', '日']
    let dd = new Date();
    var week = dd.getDay(); //获取时间的星期数

    var minus = week ? week + 6 + 7 * h : 6;
    console.log('星期' + minus)
    this.data.xqj_data = minus
    dd.setDate(dd.getDate() - minus); //获取minus天前的日期
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1; //获取月份
    var d = dd.getDate();
    let nowH = dd.getHours();
    let nowMi = dd.getMinutes();
    let nowS = dd.getSeconds();
    //切换周数
    let nowTime = y + "-" + m + "-" + d + " " + nowH + ":" + nowMi + ":" + nowS
    for (let i = 0; i < 7; i++) {
      let time = dayjs(nowTime).add(i, 'day').format("MM/DD");

      weekList.push({
        week_name: arr[i],
        week_time: time,
      });
    }
    this.data.week = weekList
    this.setData({
      week: weekList,
      nowM: m,
    })



    // return;
  },
  //请求课表
  get_kebiao(id) {
    let semesterId=null
    try{
      semesterId = wx.getStorageSync('userinfo').options.xq //起始学期
   }catch(err){
    semesterId ='262' //起始学期
   }
       
    get_kebiao({
      semesterId: semesterId,
      week: 1
    }).then(res => {
      if (res.data.statusCode == 200) {
        console.log(res);
        this.data.list = res.data.data.value
        // this.data.star_time = res.data.data.start_time
        //去掉重复的课程
        // this.data.list = Array.from(new Set(this.data.list))
        this.data.list = this.deteleObject(this.data.list)


        this.data.ke_list = res.data.data.ke

        let ke_list = {
          ke: this.data.list,
          list: this.data.ke_list
        }

        wx.setStorageSync('ke_time', res.data.data.time_list)

        this.data.time_list = res.data.data.time_list

        this.setData({
          time_list: res.data.data.time_list
        })
        this.show_kebiao(this.data.list, this.data.ke_list)
        wx.setStorageSync('ke_list', ke_list)
        wx.setStorageSync('xq', res.data.data.xq)
      } else {
        Toast('获取课表失败');
        this.setData({
          arr: [{
            type: '获取失败'
          }]
        })
      }


    }).catch(err => {
      console.log(err);
      Toast('获取课表超时,请下拉刷新');
      this.setData({
        arr: [{
          type: '获取失败'
        }]
      })
    })

    // if (this.data.is_love_kebiao) {
    this.get_qinglv_table()
    //  
    // }

  },
  //去掉相同对象
  deteleObject(obj) {
    var uniques = [];
    var stringify = {};
    for (var i = 0; i < obj.length; i++) {
      var keys = Object.keys(obj[i]);
      keys.sort(function (a, b) {
        return (Number(a) - Number(b));
      });
      var str = '';
      for (var j = 0; j < keys.length; j++) {
        str += JSON.stringify(keys[j]);
        str += JSON.stringify(obj[i][keys[j]]);
      }
      if (!stringify.hasOwnProperty(str)) {
        uniques.push(obj[i]);
        stringify[str] = true;
      }
    }
    uniques = uniques;
    return uniques;
  },

  //渲染课表
  show_kebiao(arr, ke, type) {
    //初始化课表数据
    //this.data.nowW_1
    //判断现在是否为星期天
    var d = new Date().getDay()
    let nowTime = new Date();
    let nowH = nowTime.getHours();
    console.log(nowH, d, this.data.nowW_1)

    if (nowH > 20) {
      if (d == 0) {
        this.data.nowW_1++
        console.log('加以')
      }
    } else {

    }



    let wlist = []
    for (var i = 0; i < arr.length; i++) {
      for (var j = 0; j < arr[i].value.pai6.length; j += 2) {
        var y2 = parseInt(arr[i].value.pai6[j][0].split("=")[1]);
        var x2 = parseInt(arr[i].value.pai6[j + 1][0].split("+")[1]);
        var name = arr[i].value.name.replace(/\\"|\"/g, "");
        var id = arr[i].value.id.replace(/\\"|\"/g, "");
        var room = arr[i].value.room.replace(/\\"|\"/g, "");
        var week = arr[i].value.week.replace(/\\"|\"/g, "");
        //          * 对教学周占用串进行缩略表示 marsh a string contain only '0' or '1' which named
        //  * "vaildWeeks" with length 53
        //  * 00000000000000000100000000000000000000000000000000000|
        //缩略连续周
        var vaildWeeks = [];
        for (var k = 0; k < week.length; k++) {
          if (week[k] == "1") {
            vaildWeeks.push(k);
          }
        }
        //辨别当前周
        var teacher1 = null;
        for (let j = 0; j < ke.length; j++) {
          if (ke[j].name == name) {
            teacher1 = ke[j].teacher;
          }
        }
        for (let i = 0; i < vaildWeeks.length; i++) {
          if (vaildWeeks[i] == this.data.nowW_1) {
            if (teacher1 == null) teacher1 = "未知";

            wlist.push({
              "xqj": y2 + 1,
              "skjc": x2 + 1,
              "skcd": 1,
              "kcmc": name,
              "room": room,
              "tea": `(${teacher1})`
            })

            //   this.timetables[y2][x2] =
            //     name + "(" + teacher1 + "）\n " + id + " \n" + room;

          }
        }

        //合并相同课程
        console.log(wlist);

        for (let i = 0; i < wlist.length - 1; i++) {
          if (wlist[i].kcmc == wlist[i + 1].kcmc && wlist[i].xqj == wlist[i + 1].xqj && wlist[i].room == wlist[i + 1].room&&wlist[i].skjc+1 == wlist[i + 1].skjc) {
            
            wlist[i].skcd += wlist[i + 1].skcd
            wlist.splice(i + 1, 1)
    
          }
        }



      }

    }
    console.log(wlist);
    console.log(wlist)
    this.get_dayke(wlist, type)
  },
  //获取当天课表
  get_dayke(arr, type) {
    let index = 0;
    let day = 1
    //当过了晚上10点后，预告第二天的课表
    //计算当前时间
    let nowTime = new Date();
    let nowH = nowTime.getHours();

    if (nowH > 20) {
      day = 2
      this.setData({
        day_type: day
      })
    } else {
      day = 1
      this.setData({
        day_type: day
      })
    }
    for (let i = 0; i < this.data.week.length; i++) {


      if (this.data.time == this.data.week[i].week_time) {

        index = (i + day) % (this.data.week.length + 1)
        if (index == 0) {
          index = 1
        }
      }
    }
    console.log(index)


    //筛选当日课程
    let day_arr = arr.filter(item => {

      if (index == item.xqj) {
        //匹配item.room是否包含E3

        if (item.room.indexOf("E03") != -1) {
          item.time = `${this.data.time_2[item.skjc - 1][0]}~${this.data.time_2[item.skjc + item.skcd - 2][1]}`;
        } else if (!type) {
          item.time = `${this.data.time_list[item.skjc - 1][0]}~${this.data.time_list[item.skjc + item.skcd - 2][1]}`;
        } else {
          item.time = `${this.data.time_list_love[item.skjc - 1][0]}~${this.data.time_list_love[item.skjc + item.skcd - 2][1]}`;
        }

        if (day == 2) {
          item.type = 4;
        } else {
          item.type = this.Remind(item.time)
        }


        return item
      }
    })

    console.log(index)

    //将day_arr按照时间排序
    day_arr.sort(function (a, b) {

      return a.skjc - b.skjc;
    })




    //存入缓存
    if (type) {
      wx.setStorageSync('dayke_list_love', day_arr)
      this.setData({
        arr_love: day_arr
      })
    } else {
      wx.setStorageSync('dayke_list', day_arr)
      this.setData({
        arr: day_arr
      })
    }

    // this.setData({
    //   arr: day_arr
    // })
  },
  checkdate(t1, t2) {
    let t11 = t1.split(":");
    let t21 = t2.split(":");
    let sj1 = parseInt(t11[0] * 12 + t11[1]);
    let sj2 = parseInt(t21[0] * 12 + t21[1]);

    if (sj1 < sj2) {
      return 1 //已结束
    } else if (sj1 - sj2 > 30) {

      return 3 //待开始
    } else if (sj1 > sj2) {
      return 2 //即将开始
    } else {
      return 1
    }

    // return sj1 > sj2 ? false : true;
  },
  Remind(data) {

    let t11 = data.split("~");
    let now = dayjs().format("HH:mm");
    let tipEvent = dayjs().subtract(30, "minute").format("HH:mm");
    let stime = t11[0];
    let etime = t11[1];

    if (this.checkdate(etime, now) == 1) {
      return 3; // 已结束
    } else if (this.checkdate(stime, now) == 1) {
      return 2; // 进行中
    } else if (this.checkdate(stime, now) == 2) {
      return 1; // 即将开始
    } else {
      return 0; //不显示
    }
  },

  DateDiff(sDate1, sDate2) {
    var oDate1, oDate2, iDays
    oDate1 = new Date(sDate1).getTime()
    oDate2 = new Date(sDate2).getTime()
    iDays = parseInt((oDate2 - oDate1) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数   
    return iDays
  },



  //点击宫格跳转
  tab_tiao(e) {
    if (e.currentTarget.dataset.data.type) {
      if (e.currentTarget.dataset.data.type == 'gonggao') {
        //打开弹窗
        this.showAnnouncement()
        this.setData({
          show: true,
        })
      } else if (e.currentTarget.dataset.data.type == 'img') {
        wx.navigateTo({
          url: e.currentTarget.dataset.data.url
        })
      } else if (e.currentTarget.dataset.data.type == 'waimai') {
        wx.navigateToMiniProgram({
          appId: 'wx9d5ea81cc954c751'
        })
      } else {



        if (!wx.getStorageSync('token')) {
          Dialog.confirm({
              title: '您还未登录哦',
              message: '是否现在登录',
            })
            .then(() => {
              wx.navigateTo({
                url: '/pages/login/login?url=' + e.currentTarget.dataset.data.url + '&login_type=1',

              })
            })
            .catch(() => {
              // on cancel
            });


        } else {


          if (!wx.getStorageSync('openid')) {
            this.login()
          }

          if (!wx.getStorageSync('wx_user_info')) {
            this.get_wx_info()
          }
          wx.navigateTo({
            url: e.currentTarget.dataset.data.url
          })

        }


      }

    } else if (e.currentTarget.dataset.data.url) {

      if (!wx.getStorageSync('token')) {
        Dialog.confirm({
            title: '您还未登录哦',
            message: '是否现在登录',
          })
          .then(() => {
            wx.navigateTo({
              url: '/pages/login/login?url=' + e.currentTarget.dataset.data.url,

            })
          })
          .catch(() => {
            // on cancel
          });

      } else {
        wx.navigateTo({
          url: e.currentTarget.dataset.data.url
        })
        //  }


      }

    }





  },







  //开启空调
  kaiqi: function () {

    this.data.stuta = !this.data.stuta

    this.setData({
      statu: this.data.stuta
    })
  },

  length() {
    this.data.type = 0
    this.setData({
      type: this.data.type
    })

  },
  re() {
    this.data.type = 1
    this.setData({
      type: this.data.type
    })

  },
  up() {
    this.data.wendu++
    if (this.data.wendu > 32) {
      wx.showModal({
        title: '提示',
        content: '再升高温度我就要爆啦哦',
        success(res) {
          if (res.confirm) {

          } else if (res.cancel) {

          }
        }
      })
      this.data.wendu = 32
      return
    }


    this.setData({
      wendu: this.data.wendu
    })
  },
  jiang() {
    if (this.data.wendu < 17) {
      wx.showModal({
        title: '提示',
        content: '现在是冬天哦',
        success(res) {
          if (res.confirm) {

          } else if (res.cancel) {

          }
        }
      })
      this.data.wendu = 16
      return
    }
    this.data.wendu--


    this.setData({
      wendu: this.data.wendu
    })
  },

  //获取情侣课表
  get_qinglv_table() {
    get_qinglv(242).then(res => {

      if (res.data.statusCode == 200) {
        this.data.list = res.data.data.value
        //去掉重复的课程
        // this.data.list = Array.from(new Set(this.data.list))
        this.data.list = this.deteleObject(this.data.list)


        this.data.ke_list = res.data.data.ke

        let ke_list = {
          ke: this.data.list,
          list: this.data.ke_list
        }

        wx.setStorageSync('ke_time_love', res.data.data.time_list)

        this.data.time_list = res.data.data.time_list

        this.setData({
          time_list_love: res.data.data.time_list
        })
        this.show_kebiao(this.data.list, this.data.ke_list, true)
        wx.setStorageSync('ke_list_love', ke_list)

        //修改缓存user用户信息
        let user = wx.getStorageSync('user')
        user.birthday = 123345,
          //存入缓存
          wx.setStorageSync('user', user)


        this.data.is_love_kebiao = true
        this.setData({

          is_love_kebiao: true
        })

      } else if (res.data.statusCode == 400) {

        if (res.data.message == '暂无绑定！') {
          this.data.is_love_kebiao = false
          //修改缓存user用户信息
          let user = wx.getStorageSync('user')
          user.birthday = null,
            //存入缓存
            wx.setStorageSync('user', user)
          //清除缓存
          wx.removeStorageSync('ke_list_love'),
            wx.removeStorageSync('dayke_list_love'),
            wx.removeStorageSync('ke_time_love')


          this.setData({

            is_love_kebiao: false
          })
        } else {
          Toast('获取对方课表超时,可能对方登录过期');
          this.setData({
            arr_love: [{
              type: '获取失败'
            }]
          })
        }

      }

    })
  },

  onLoad(options) {

    //获取当前时间戳
    let new_time = dayjs().valueOf();
    //判断时间戳
    console.log(new_time)
    try {
      if (options.id) {
        if (options.timestamp > new_time) {
          //弹窗提示绑定信息
          Dialog.confirm({
              confirmButtonText: '同意',
              title: '情侣课表绑定',
              message: '你是否同意绑定该情侣课表'
            })
            .then(() => {


              if (!wx.getStorageSync('token')) {
                Dialog.confirm({
                    title: '您还未登录哦',
                    message: '是否现在登录',
                  })
                  .then(() => {
                    wx.navigateTo({
                      url: '/pages/login/login?url=/pages/index/index&id=' + options.id + '&timestamp=' + options.timestamp,
                    })
                  })
                  .catch(() => {
                    // on cancel
                  });

              } else {
                //跳转
                bind_qinglv({
                  id: '242',
                  toStuId: options.id,
                  week: '1'
                }).then(res => {

                  if (res.data.statusCode == 200) {
                    //提示绑定成功
                    Toast('绑定成功💕');
                    this.get_kebiao(242)
                  } else {
                    Toast(res.data.message);
                  }
                })
              }


            })
            .catch(() => {
              // on cancel
            })
        } else {
          Toast('绑定链接已过期，请重新获取');
        }

      }
    } catch (e) {}



    //判断是否未打开公告
    // if (!wx.getStorageSync('is_open_announcement')) {
    //   this.setData({
    //     show: true,
    //   })
    // } else {

    // }



    this.setData({

      grid_list: this.data.grid_list,

    })
  },
  //版本号对比
  compareVersion(v1, v2) {
    v1 = v1.split('.')
    v2 = v2.split('.')
    const len = Math.max(v1.length, v2.length)

    while (v1.length < len) {
      v1.push('0')
    }
    while (v2.length < len) {
      v2.push('0')
    }

    for (let i = 0; i < len; i++) {
      const num1 = parseInt(v1[i])
      const num2 = parseInt(v2[i])

      if (num1 > num2) {
        return 1
      } else if (num1 < num2) {
        return -1
      }
    }

    return 0
  },
  /**
   * 启动定时器
   */
  startInter: function () {
    let that = this
    that.data.gg_index = 0

    that.data.inter = setInterval(
      function () {
        // TODO 你需要无限循环执行的任务

        that.data.gg_index++
        if (that.data.gg_index < that.data.gonggao_list.length) {

          that.setData({
            gg: that.data.gonggao_list[that.data.gg_index].text
          })

        } else {
          that.data.gg_index = 0
          that.setData({
            gg: that.data.gonggao_list[that.data.gg_index].text
          })
        }
      }, 10000);
  },

  /**
   * 结束定时器
   */
  endInter: function () {

    clearInterval(this.data.inter)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onHide: function () {
    this.endInter()

  },


  async onShow() {
    // this.get_kebiao(242)
    let user = wx.getStorageSync('userinfo')
    if (user) {
      wx.reportEvent("a2", {
        "user_name": user.name.value,
        "xy": user.Department.value,
        "bj": user.class.value,
        "xh1": user.stuNumber.value
      })
    }


    // this.get_user_num()
    let new_time = dayjs().valueOf();
    try {
      if (app.globalData.id) {
        if (app.globalData.time > new_time) {
          bind_qinglv({
            id: '242',
            toStuId: app.globalData.id,
            week: '1'
          }).then(res => {

            if (res.statusCode == 200) {
              //提示绑定成功
              Toast('绑定成功🥰');
              this.get_kebiao(242)
              app.globalData.id = null
            }
          })
        } else {
          Toast('绑定链接已过期，请重新获取');
        }


      }
    } catch (e) {}


    this.getUserInfo()

    this.showAnnouncement()
    this.get_lunbo()
    this.updated()

    this.startInter()
    this.getWeekList()
    await get_show().then(res => {

      if (res.data.password == app.getVersion()) {
        this.data.type_1 = res.data.stuNumber

      } else {
        this.data.type_1 = 'false'

      }
      if (res.data.nativeplace == 1) {
        console.log(this.data.grid_list[0][1])
        this.data.grid_list[0][1].is_open = 0
        this.setData({
          grid_list: this.data.grid_list
        })

      } else {
        this.data.grid_list[0][1].is_open = 1
        this.setData({
          grid_list: this.data.grid_list
        })
      }
      if (this.data.request_type == 1) {
        Toast('刷新成功~');
      }



    }).catch(err => {
      // Toast('网络异常~');
    });
    this.data.request_type = 0
    if (wx.getStorageSync('ke_list')) {
      this.data.time_list = wx.getStorageSync('ke_time')
      let ke_list = wx.getStorageSync('ke_list')

      this.show_kebiao(ke_list.ke, ke_list.list, false);



    } else {
      if (wx.getStorageSync('token')) {
        this.get_kebiao(242)
      }

    }

    if (wx.getStorageSync('ke_list_love')) {
      this.data.time_list_love = wx.getStorageSync('ke_time_love')
      let ke_list_love = wx.getStorageSync('ke_list_love')
      this.show_kebiao(ke_list_love.ke, ke_list_love.list, true);

    } else {
      if (wx.getStorageSync('token')) {
        this.get_qinglv_table()
      }

    }


    wx.stopPullDownRefresh()
    this.setData({
      type_1: this.data.type_1,
      statu: this.data.stuta,
      arr: wx.getStorageSync('dayke_list'),
      user: wx.getStorageSync('userinfo'),



    })
    setTimeout(() => {
      this.setData({

        user: wx.getStorageSync('userinfo')
      })
      this.getWeather()
    }, 500)
    let that = this
    wx.getSystemInfo({
      success(res) {
        that.setData({
          basic_version: res.SDKVersion
        })
      }
    })

  },

  //下拉刷新
  onPullDownRefresh() {
    wx.vibrateShort({
      type: 'heavy',
      success: res => {
        console.log(res)
      }
    })
    this.data.request_type = 1

    setTimeout(() => {
      this.endInter()
      this.onLoad()
      this.onShow()
      wx.stopPullDownRefresh();
    }, 1000)


    //判断刷新成功
    // wx.hideLoading()
    //提示刷新成功






  },
  onPageScroll(e) {



    let {
      windowHeight
    } = wx.getSystemInfoSync()


    const query = wx.createSelectorQuery()
    query.select('.people_num').boundingClientRect()

    query.exec(rect => {
      let {
        top,
        height
      } = rect[0]
      height = parseInt(height)
      top = parseInt(top)
      windowHeight = parseInt(windowHeight)

      // windowHeight = top（目标元素刚进入可视区域）
      // windowHeight - top = height（目标元素完全进入可视区域）
      // top = 0 (目标元素刚离开可视区域)
      // top + height = 0 （目标元素完全离开可视区域 ）




      if (windowHeight - top > height) {


      } else {
        this.data.hh()
        //  this.setData({
        //   people_num: '000'
        // })
      }
    })
  },


  throttle(time = 100) {
    var t = null;
    var that = this
    return function () {
      if (t) return;
      t = setTimeout(() => {

        that.setData({
          people_num: '000'
        })
        t = null;
      }, time);
    }
  },
  onReady: function () {
    this.data.hh = this.throttle()

  },





  onReachBottom() {
    wx.vibrateShort({
      type: 'heavy',
      success: res => {
        console.log(res)
      }
    })

    this.get_user_num()

  }

})